import Vue from 'vue'
import VueRouter from 'vue-router'
import store from "@/wwwroot/js/vuex.js";
import global from "@/wwwroot/js/global.js";

Vue.use(VueRouter) // 注册vue-router

const router=new VueRouter({
    mode: 'history',
    routes: [{
        path: '/',
        name: 'Login',
        meta: {title: '登录'},
        component: ()=>import('@/components/Login.vue')
      },{
        path: '/Home',
        component: ()=>import('@/components/Home.vue'),
        children:[
          {
            path:'/',
            name:'HomeDefault',
            meta:
            {
              title:"首页",
              keepAlive:true
            },
            component: ()=>import('@/components/pages/HomeDefault.vue')
          },{
            path:'/AuthDetail',
            name:'AuthDetail',
            meta:
            {
              title:"授权列表",
              keepAlive:true
            },
            component: ()=>import('@/components/pages/AuthDetail.vue')
          },{
            path:'/LogDetail',
            name:'LogDetail',
            meta:
            {
              title:"日志列表",
              keepAlive:true
            },
            component: ()=>import('@/components/pages/LogDetail.vue')
          }
        ]
      }]
  })

  router.beforeEach((to, from, next) => {
    if (to.name=='Login')  {
      next()
    }else if (to.meta.title) {
      document.title=to.meta.title;
      store.commit('pageJump', to)
      next()
    }else {
      console.error(to)
      global.toast('页面路径无效')
    }
  });

export default router
